import itertools
class BasePlayer(object):
    def __str__(self):
        try:
            return self.name
        except AttributeError:
            # Fall back on Python default
            return super(BasePlayer, self).__repr__()

    def hunt_choices(*args, **kwargs):
        raise NotImplementedError("You must define a strategy!")

    def hunt_outcomes(*args, **kwargs):
        pass

    def round_end(*args, **kwargs):
        pass

class Player(BasePlayer):

    def __init__(self, name):
        if name:
            self.name = name
        else:
            self.name="Tanishq Aggarwal 2"
        self.player_numbers = []
        self.player_reputation_record = []

    def hunt_choices(self, round_number, current_food, current_reputation, m, player_reputations):
        self.round_number = round_number
        self.player_reputation_record.append(player_reputations)
        if round_number == 1:
            self.player_numbers.append(len(player_reputations) + 1)
            self.player_reputation_record.append(player_reputations)
            if m <= len(player_reputations):
                decisions = self.m_maximization_rounds_3_to_end(m, player_reputations)
                return decisions
            else:
                return ['s']*len(player_reputations)

        elif round_number == 2: #comment: change the hunt decisions to hunt with the top M reputations
            self.player_numbers.append(len(player_reputations) + 1)
            self.player_reputation_record.append(player_reputations)
            if m <= len(player_reputations):
                decisions = self.m_maximization_rounds_3_to_end(m, player_reputations)
                return decisions
            else:
                return ['s']*len(player_reputations)

        elif 3 <= round_number <= 100:
            self.player_numbers.append(len(player_reputations) + 1)
            self.player_reputation_record.append(player_reputations)
            self.pattern_analysis(self.player_tracker(self.hunt_matrix_create()))
            if m <= len(player_reputations):
                decisions = self.m_maximization_rounds_3_to_end(m, player_reputations)
                return decisions
            else:
                return ['s']*len(player_reputations)

        elif round_number >= 100:
            self.player_numbers.append(len(player_reputations) + 1)
            self.player_reputation_record.append(player_reputations)
            if m <= len(player_reputations):
                decisions = self.m_maximization_rounds_3_to_end(m, player_reputations)
                return decisions
            else:
                return ['s']*len(player_reputations)
        
    def m_maximization_rounds_3_to_end(self, m, player_reputations): #To be modified, but in a last-minute scenario this is fine
	'''currently the code is based on reputation, later it should be on pattern analysis'''
        def count(x, lst):
            ind = []
            for i in lst:
                if i == x:
                    ind.append(lst.index(x))
            return ind
        player_reputations.sort()
        shortened_reps = player_reputations[m - 1:]
        hunt_decisions = ['s']*len(self.player_reputation_record[-1])
        for i in shortened_reps:
            indices = count(i, self.player_reputation_record[-1])
            for q in indices:
                hunt_decisions[q] = 'h'
        return hunt_decisions
        
    def hunt_outcomes(self, food_earnings): #Nothing to do here
        pass

    def round_end(self, award, m, number_hunters): #Nothing to do here
        pass 